<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<style type="text/css">

.red
{ 
	font-size:30px;
	color:red;
}
.gray
{
background:#ccc;
}

.pink
{
background:pink;
}

</style>

<!-- 导入jquery核心类库 -->
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<!-- 导入easyui类库 -->
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/ext/portal.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/css/default.css">	
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.portal.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.cookie.js"></script>
<script
	src="${pageContext.request.contextPath }/js/easyui/locale/easyui-lang-zh_CN.js"
	type="text/javascript"></script>
		
<script type="text/javascript">
	$(function(){
		$("body").css({visibility:"visible"});
		//提交表单
		
		 $('#save').click(function(){
			 
			 //清除CSS
			 	$('#tab tr').each(function(){
			 		/* $("#"+this.id).removeClass("gray");
			 		$("#"+this.id).removeClass("pink"); */
			 		$("#"+this.id).removeClass();
			 		
			 	});
			 
			//自动填充后台表单
			$("#iRNumber").val($("#oOPNumber").html());
			 
			 var flag=true;
			$('#sform :input').each(function(){				
				if(this.value==-1 || this.value==null||this.value==""){
					flag=false;
					
				}
			});
			
			if($("#oOPNumber").html()==0){
				$.messager.alert('消息','没有任何尺子入库，处理失败！ ','warnning', function(){
					location.href="${pageContext.request.contextPath}/page.inputrulerevent.ashx"
				});
				return;
			}
				// 校验
				if(flag){
					
					// 1 、获得form 数据
					var params = $('#sform').serialize();
					// 2、将数据发送给服务器 
					$.post("${pageContext.request.contextPath}/page.processInputRuler.ashx", params , function(data){
						//alert(data)
						
						if(data.status == "1"){
							// 成功
							$.messager.alert('消息','操作成功 ','info', function(){
								location.href="${pageContext.request.contextPath}/page.inputrulerevent.ashx"
							});
							
						
						}else if(data.status==("3")){
							var id=new String(data.id).split("_")[1];
								$.messager.alert('消息','请检查"<font color=red>产品条码_'+id+'</font>"的值.<br>库存中未找到SN为"<font color=red>'+data.sn+'</font>"状态为"<font color=red>已调试待入库</font>"的E尺','info');								
								//$("#"+data.id).parents('tr').css('background', '#ccc');
								//$("#"+data.id).css('background', '#ccc');
								$("#"+data.id).addClass("gray");
								
								
								
						}else if(data.status==("0")){
								$.messager.alert('消息','<br>SN号'+data.sn+'重复!','info');
								
								$('#sform :input').each(function(){	
									
									if(this.value==data.sn){
										//$("#"+this.id).css('background', 'pink');	
										$("#"+this.id).addClass("pink");
									}
								});
								
						}
							
					});
				}else{
					$.messager.alert("提示", "请检查输入项是否有遗漏未输入","warnning");
				}
				
			});	
	});
	
	
	
	$(document).ready(function(){
		$('input#opcode_1').focus();
		
		 $('input#opcode_1').bind('input oninput', function() {  
		    //$('#result').html($(this).val().length + ' characters');  
		    if($(this).val().length==8){
		    	$('input#opcode_2').focus();
		    }
		});
		
		//动态生成表单
      	var a = $("#oOPNumber").html();
    	for(i=0;i<a-1;i++){
    		
    	
           var _len = $("#tab tr").length;        
           $("#tab").append("<tr id='opcode_"+_len+"'><td>产品条码_"+_len+":</td>"
           						 +"<td><input type='text' name='opcode_"+_len+"' id='opcode_"+_len+"' class='easyui-textbox' />"
           						 +"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a id='opcode_"+_len+"' href='#' onclick='doDel(this.id)' >删除</a>"
           						 +"</td></tr>" );
           
    	}
    	
    	var  _len= $("#tab tr").length;    
    	for(i=2;i<=_len;i++){
    		
    		$('input#opcode_'+i).bind('input oninput', function() {  
    		    if($(this).val().length==8){
    		    	
    		    	$(this).parents('tr').next().find('input').focus();
    		    	
    		    	
    		    }
    		});
    		
    	}
    
	
    	
    	
	}); 
	function doDel(id){
		
		//alert(id)
		$("#"+id).remove();
		$("#oOPNumber").html($("#oOPNumber").html()-1);
		$("#oOPNumber").addClass("red");
	}
	window.onload=function(){
		//基本信息格式化
		$("#oDealTime").html(formatterDate($("#oDealTime").html()));
		$("#oITime").html(formatterDate($("#oITime").html()));
		$("#oIsDone").html($("#oIsDone").html()==0?"未处理":"已处理");
	}
	function formatterDate(value){
		if(value==''||null==value){
			return '';
		}
		var now = new Date(parseInt(value) * 1000);  
		var year=now.getYear()+1900; 
		var month=now.getMonth()+1; 
		var date=now.getDate(); 
		var hour=now.getHours(); 
		var minute=now.getMinutes();
		minute= (minute > 9) ? minute=minute : minute='0'+minute;
		//var second=now.getSeconds(); 
		return year+"-"+month+"-"+date+" "+hour+":"+minute; 
	}
</script>

	
</head>

<body class="easyui-layout" style="visibility:hidden;">
	<div region="north" style="height:31px;overflow:hidden;" split="false" border="false" >
		<div class="datagrid-toolbar">
			<a id="save" icon="icon-save" href="#" class="easyui-linkbutton" plain="true" >保存</a>
			
		</div>
	</div>
    <div region="center" style="overflow:auto;padding:5px;" border="false">
         <table class="table-edit"  width="95%" align="center">
           		<tr class="title"><td colspan="6">基本信息</td></tr>
 
	
	           	<tr>
	           		
	           		<td>申请人:</td>
	           		<td>${ir.iRProposer}</td>
					<td>入库数量:</td>
					<td id="oOPNumber">${ir.iRNumber}</td>
				</tr>  	 	<tr>
	           		<td>处理状态</td>
					<td id="oIsDone">${ir.iRIsDone}</td>
					<td>经手人:</td>
					<td>${ir.iRStorekeeper}</td>
				</tr>  	<tr>
	           		
					<td>备注:</td>
	           		<td >${ir.iRRemark}</td>
	           		
				</tr> 
			</table>
           <form id="sform">  
           <input name="iRId" id="iRId" type="hidden" value="${ir.iRId}" />
           <input name="iRNumber" id="iRNumber" type="hidden"/>
			<table id="tab" class="table-edit"  width="95%" align="center">
			
				<tr class="title"><td colspan="6">产品信息</td></tr>
				 <tr id="opcode_1">	<td>产品条码_1:</td>
						<td><input type="text"  name="opcode_1" id="opcode_1"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a id="opcode_1" href="#" onclick="doDel(this.id)" >删除</a></td>
						
	           			
				</tr>
	           
	         </table> 
	  	
	    
				
         
     </form> 
	</div>
</body>
</html>